<template>
  <view v-if="listData.length > 0">
    <view class="grid-body mt-30" v-for="item in listData" :key="item.id">
      <view class="check grid-common">
        <view class="flex text"
          >所属检查子类：<text> {{ item.subCheckType }}</text></view
        >
        <view class="flex text"
          >计划编码：<text>{{ item.taskCode }}</text></view
        >
        <view class="flex text"
          >排查地点：<text>{{ item.checkLocation }}</text></view
        >
        <view class="flex text"
          >计划名称：<text> {{ item.taskName }}</text></view
        >
        <view class="flex text"
          >计划排查开始时间：<text> {{ item.planCheckStartTime }}</text></view
        >
        <view class="flex text"
          >计划排查结束时间：<text> {{ item.planCheckEndTime }}</text></view
        >
        <view class="footer-wrap">
          <view class="content-wrap"> </view>
          <view class="button-wrap">
            <button class="button" @click="goViewCheckItem(item.id)">查看排查项</button>
            <button class="button button-orange" @click="goDeal(item.id)">处理</button>
          </view>
        </view>
      </view>
    </view>
  </view>
  <view v-else>
    <Empty></Empty>
  </view>
</template>

<script>
import { hiddenDangerDispatchList } from '@/api/dbd/hiddenDangerCheck.js'
import Empty from '@/components/cu-empty/index.vue'
export default {
  components: {
    Empty
  },
  data() {
    return {
      listData: [],
      pageNum: 1,
      total: null
    }
  },
  onLoad() {
    this.initData()
  },
  onPullDownRefresh() {
    this.initData()
  },
  onReachBottom() {
    this.pageNum++
    this.getList()
  },
  methods: {
    initData() {
      this.pageNum = 1
      this.total = null
      this.getList()
    },
    getList() {
      if (!this.total || this.total > this.listData.length) {
        hiddenDangerDispatchList({
          pageNum: this.pageNum
        }).then((res) => {
          if (this.pageNum === 1) {
            this.listData = res.rows
          } else {
            this.listData.push(...res.rows)
          }
          this.total = res.total
          uni.stopPullDownRefresh()
        })
      }
    },
    goViewCheckItem(id) {
      uni.navigateTo({
        url: '/pages/work/hiddenDangerDispatch/check-item?id=' + id,
        events: {
          // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
          'callback:reload': () => {
            this.initData()
          }
        }
      })
    },
    goDeal(id) {
      uni.navigateTo({
        url: '/pages/work/hiddenDangerDispatch/item?id=' + id,
        events: {
          // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
          'callback:reload': () => {
            this.initData()
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.check {
  position: relative;

  .title {
    font-size: 34rpx;
    font-weight: 700;
  }

  .icon-style {
    width: 52rpx;
    height: 52rpx;
    margin-right: 20rpx;
  }

  .text {
    color: #999;

    text {
      width: 60%;
      color: #333;
      display: inline-block;
    }
  }

  .bor-top {
    padding-top: 20rpx;
    border-top: 1px solid #d5d7e3;
  }

  .check-right-top {
    position: absolute;
    right: 20rpx;
    top: 40rpx;

    image {
      width: 100rpx;
      height: 88rpx;
    }
  }
}
.info-btn {
  margin: 0 5px;
}
</style>
